package finalproject.client;

import java.util.List;


import finalproject.client.ProjectService;
import finalproject.client.ProjectServiceAsync;
import finalproject.client.StudentGui;
import finalproject.shared.Student;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;

public class StudentClass {
	  private ProjectServiceAsync ProjectService = GWT.create(ProjectService.class);
	    StudentGui gui;
	    
	   // student list 
	    
	    void listStudenten() {
	    	ProjectService.listStudenten(new AsyncCallback<List<Student>> () {
	                    public void onFailure(Throwable caught) {
	                        gui.service_eventListStudentenFailed(caught);
	                    }
	        
	                    public void onSuccess(List<Student> result) {
	                        gui.service_eventListRetrievedFromService(result);
	                        
	                    }
	        }
	        );
	    }
	    
	   
	      //Add the student.
	     
	    
	    void addStudent(final Student student) {
	    	ProjectService.addStudent(student, new AsyncCallback<Void> () {
	            public void onFailure(Throwable caught) {
	                gui.service_eventAddStudentFailed(caught);
	            }

	            public void onSuccess(Void result) {
	                gui.service_eventAddStudentSuccessful();
	            }
	        }
	        );   
	    }

	   
	     // Update student.
	   
	    void updateStudent(final Student student) {
	    	ProjectService.updateStudent(student, new AsyncCallback<Void> () {
	            public void onFailure(Throwable caught) {
	                gui.service_eventUpdateStudentFailed(caught);
	            }

	            public void onSuccess(Void result) {
	                gui.service_eventUpdateSuccessful();
	            }
	        }
	        );        
	    }

	   
	     // verwijder  student.
	  
	    void removeStudent(final Student student) {
	    	ProjectService.removeStudent(student, new AsyncCallback<Void> () {
	            public void onFailure(Throwable caught) {
	                gui.service_eventRemoveStudentFailed(caught);
	            }

	            public void onSuccess(Void result) {
	                gui.service_eventRemoveStudentSuccessful();
	            }
	        }
	        );  
	    }
	    
	}

